package com.youme

import android.content.Context
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.launcher.ARouter
import com.salton123.log.XLog

/**
 * @Time:2021/3/30 9:42
 * @Author:wujinsheng
 * @Description:
 */
object RouterManager {
    private const val TAG = "RouterManager"

    interface KEY {
        companion object {
            const val ITEM_KEY = "item_key"
        }
    }

    fun smsLogin(fromContext: Context) {
//        test(fromContext)   //暂时跳转到测试页面，实现登录功能
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.SMS_LOGIN
        ARouter.getInstance()
            .build(path)
            .navigation(fromContext)
    }

    fun register(fromContext: Context) {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.REGISTER
        ARouter.getInstance()
            .build(path)
            .navigation(fromContext)
    }


    @JvmOverloads
    fun main(fromContext: Context, itemKey: String = "") {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.MAIN
        ARouter.getInstance()
            .build(path)
            .withTransition(0, 0)
            .withString(KEY.ITEM_KEY, itemKey)
            .navigation(fromContext)
    }

    fun address(fromContext: Context) {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.ADDRESS
        ARouter.getInstance()
            .build(path)
            .navigation(fromContext)
    }

    fun about(fromContext: Context) {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.ABOUT
        ARouter.getInstance()
            .build(path)
            .navigation(fromContext)
    }

    fun order(fromContext: Context) {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.ORDER
        ARouter.getInstance()
            .build(path)
            .navigation(fromContext)
    }

    @JvmOverloads
    fun discoverDetail(fromContext: Context, circleId: String) {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.DISCOVER_DETAIL
        ARouter.getInstance()
            .build(path)
            .withString("circleId", circleId)
            .navigation(fromContext)
    }

    fun profilePage(): Fragment {
        XLog.i(TAG, "get profilePage")
        val path = Constants.Router.YOUME.PROFILE
        return ARouter.getInstance()
            .build(path)
            .navigation() as Fragment
    }

    fun homePage(): Fragment {
        XLog.i(TAG, "get homePage")
        val path = Constants.Router.YOUME.HOME
        return ARouter.getInstance()
            .build(path)
            .navigation() as Fragment
    }

    fun discoverPage(): Fragment {
        XLog.i(TAG, "get discoverPage")
        val path = Constants.Router.YOUME.CONTACT_LIST
        return ARouter.getInstance()
            .build(path)
            .navigation() as Fragment
    }

    fun conversationListPage(): Fragment {
        XLog.i(TAG, "get conversationListPage")
        val path = Constants.Router.YOUME.CONVERSATION_LIST
        return ARouter.getInstance()
            .build(path)
            .navigation() as Fragment
    }

    fun policy(fromContext: Context) {
        XLog.i(TAG, "from:${fromContext.javaClass.canonicalName}")
        val path = Constants.Router.YOUME.POLICY
        ARouter.getInstance()
            .build(path)
            .navigation(fromContext)
    }
}